<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no"/>
    <title>奖学金管理页面</title>
    <link rel="stylesheet" type="text/css" href="../static/admin/layui2/css/layui.css"/>
</head>
<body class="layui-layout-body">
<div class="layui-layout layui-layout-admin">
    <div class="layui-header">
        <div class="layui-logo"><a href="guanliyuan-main.html" style="color: #009688;font-size: 25px;">管理员主页面</a></div>
        <!-- 头部区域（可配合layui已有的水平导航） -->
        <ul class="layui-nav layui-layout-right">
            <li class="layui-nav-item"><a class="layui-icon layui-icon-user" style="color:#009688;font-size: 20px;text-align: center;" href="student-login.html">学生登录</a></li>
            <li class="layui-nav-item"><a class="layui-icon layui-icon-logout" style="color: #ff3c00;font-size: 20px;text-align: center;" href="guanliyuan-login.html">退出</a></li>
        </ul>
    </div>

    <div class="layui-side layui-bg-black">
        <div class="layui-side-scroll">
            <!-- 左侧导航区域（可配合layui已有的垂直导航） -->
            <ul class="layui-nav layui-nav-tree"  lay-filter="test">
                <li class="layui-nav-item">
                    <a href="javascript:;"><i class="layui-icon layui-icon-username" style="font-size: 24px; color: #009688; margin-right: 16px"></i> 信息管理</a>
                    <dl class="layui-nav-child">
                        <dd><a href="guanliyuan-mimaChange.html"><i class="layui-icon layui-icon-edit" style="font-size: 24px; color: #009688; margin-right: 16px"></i>修改密码</a></dd>
                        <dd><a href="guanliyuan-add.html"><i class="layui-icon layui-icon-add-circle" style="font-size: 24px; color: #009688; margin-right: 16px"></i>添加管理员</a></dd>
                    </dl>
                </li>
                <li class="layui-nav-item">
                    <a href="javascript:;"><i class="layui-icon layui-icon-user" style="font-size: 24px; color: #009688; margin-right: 16px"></i>员工管理</a>
                    <dl class="layui-nav-child">
                        <dd><a href="guanliyuan-addstudent.html"><i class="layui-icon layui-icon-add-circle" style="font-size: 24px; color: #009688; margin-right: 16px"></i>添加员工</a></dd>
                        <dd><a href="guanliyuan-deletestudent.html"><i class="layui-icon layui-icon-reduce-circle" style="font-size: 24px; color: #009688; margin-right: 16px"></i>删除员工</a></dd>
                    </dl>
                </li>
                <li class="layui-nav-item">
                    <a href="javascript:;"><i class="layui-icon layui-icon-group" style="font-size: 24px; color: #009688; margin-right: 16px ;"></i>校友管理</a>
                    <dl class="layui-nav-child">
                        <dd><a href="guanliyuan-addalumni.html"><i class="layui-icon layui-icon-add-circle" style="font-size: 24px; color: #009688; margin-right: 16px"></i>添加校友</a></dd>
                        <dd><a href="guanliyuan-alumni.html"><i class="layui-icon layui-icon-friends" style="font-size: 24px; color: #009688; margin-right: 16px"></i>校友信息</a></dd>
                    </dl>
                </li>
                <li class="layui-nav-item layui-nav-iteme">
                    <a href="javascript:;"><i class="layui-icon layui-icon-rmb" style="font-size: 24px; color: #009688; margin-right: 16px"></i>奖学金管理</a>
                    <dl class="layui-nav-child">
                        <dd><a href="guanliyuan-addscholarship.html"><i class="layui-icon layui-icon-add-circle" style="font-size: 24px; color: #009688; margin-right: 16px"></i>添加奖学金</a></dd>
                        <dd><a href="guanliyuan-scholarship.html"><i class="layui-icon layui-icon-file" style="font-size: 24px; color: #009688; margin-right: 16px"></i>奖学金信息</a></dd>
                    </dl>
                </li>
                <li class="layui-nav-item layui-nav-iteme">
                    <a href="guanliyuan-examine.html" class="layui-this"><i class="layui-icon layui-icon-survey" style="font-size: 24px; color: #009688; margin-right: 16px"></i>审批</a>
                </li>
            </ul>
        </div>
    </div>

    <div class="layui-body">
        <div class="demoTable" style="margin-top: 10px;margin-left: 10px">
            <div class="layui-inline" >
                <input class="layui-input" name="id" id="demoReload" autocomplete="off">
            </div>
            <button id="searchBtn" class="layui-btn" data-type="reload"><i class="layui-icon layui-icon-search"></i></button>
        </div>
        <!-- 内容主体区域 -->
        <div class="layui-anim layui-anim-scale">
            <script type="text/html" id="toolbar0">
                <a class="layui-btn layui-btn-primary layui-icon layui-icon-delete" style="font-size: 20px;" lay-event="add"></a>-->
            </script>
            <table class="layui-hide" id="demo" lay-filter="test"></table>
            <script type="text/html" id="barDemo">
                <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="updata">操作</a>
                <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
            </script>
            <script type="text/html" id="table-gender">
                {{# if(d.gender== 0) { }}
                女
                {{# } else if(d.gender== 1){ }}
                男
                {{# } else { }}
                保密
                {{# } }}
            </script>
            <script type="text/html" id="table-state">
                {{# if(d.state== 0) { }}
                <label style="color: lightseagreen">未审批</label>
                {{# } else if(d.state== 1){ }}
                <label style="color: #00b5f9">通过</label>
                {{# } else { }}
                <label style="color: red">未通过</label>
                {{# } }}
            </script>
        </div>
    </div>

    <div class="layui-footer layui-bg-green">

    </div>
</div>
<script src="../static/admin/layui2/layui.js" type="text/javascript" charset="utf-8"></script>
<script>
    layui.use(['laydate', 'laypage', 'layer', 'table', 'jquery', 'element'], function() {
        var laydate = layui.laydate //日期
            , layer = layui.layer //弹层
            , table = layui.table //表格
            , $ =layui.jquery
            , element = layui.element //元素操作

        table.render({
            elem: '#demo'
            ,height: 600
            ,url: "/scholarshipApply/showExamine" //数据接口
            ,title: '奖学金信息'
            ,toolbar: 'default' //自定义工具栏
            ,totalRow: true //开启合计行
            ,parseData:function(map) {//格式绑定后端传递过来的数据，我使用的是map对象，为了符合数据表格接受数据的样式，所以这么做的
                return {
                    "code":map["code"],
                    "msg":"",
                    "count":map["count"],
                    data:map["data"]//这个data才是表格所需要的数据，里面其实是一个list集合，存放的是n条数据记录。
                }
            }
            ,cols: [[ //表头
                {type: 'checkbox', fixed: 'left'}
                ,{field: 'id',title: '申请单编号', width:120,sort: true}
                ,{field: 'gender', title: '状态', width: 80,templet: '#table-state' ,sort: true}
                ,{field: 'sname',title: '奖学金名', width:120}
                ,{field: 'money',title: '金额', width:90,sort: true}
                ,{field: 'residue', title: '剩余名额', width: 110,sort: true}
                ,{field: 'applyNum', title: '申请人数', width: 110,sort: true}
                ,{field: 'number', title: '申请人学号', width:120,sort: true}
                ,{field: 'name',title: '申请人姓名', width:110}
                ,{field: 'clazz', title: '班级', width:100,sort: true}
                ,{field: 'gender', title: '性别', width: 80,templet: '#table-gender' ,sort: true}
                ,{field: 'department', title: '学院', width: 120}
                ,{field: 'major', title: '专业', width: 100}
                ,{fixed: 'right', width: 165, align:'center', toolbar: '#barDemo'}
            ]],
            page: true //开启分页
            , limits: [2,5]  //一页选择显示3,5或10条数据
            , limit: 2 //一页显示6条数据
        });

        table.on('toolbar(test)', function(obj){
            var checkStatus = table.checkStatus(obj.config.id)
                ,data = checkStatus.data; //获取选中的数据
            switch(obj.event){
                case 'add':
                    layer.open({
                        type: 2
                        ,
                        title: "添加信息"
                        ,
                        skin: 'layui-layer-molv'
                        ,
                        area: ['600px', '700px']
                        ,
                        id: 'LAY-1' //设定一个id，防止重复弹出
                        ,
                        btnAlign: 'd'
                        ,
                        moveType: 0 //拖拽模式，0或者1
                        ,
                        fixed: false,
                        content: "guanliyuan-addalumni.html",
                        shadeClose: true,
                    })
                    break;
                case 'update':
                    if(data.length === 0){
                        layer.msg('请选择一行');
                    } else if(data.length > 1){
                        layer.msg('只能同时编辑一个');
                    } else {
                        layer.alert('编辑 [id]：'+ checkStatus.data[0].id);
                    }
                    break;
                case 'delete':
                    if(data.length === 0){
                        layer.msg('请选择一行');
                    } else {
                        layer.msg('删除');
                    }
                    break;
            };
        });

        table.on('tool(test)', function(obj){ //注：tool 是工具条事件名，test 是 table 原始容器的属性 lay-filter="对应的值"
            var data = obj.data //获得当前行数据
                ,layEvent = obj.event; //获得 lay-event 对应的值
            if(layEvent === 'updata'){
                layer.open({
                    type: 2
                    ,
                    title: "修改信息"
                    ,
                    skin :'layui-layer-molv'
                    ,
                    area: ['600px','750px']
                    ,
                    id: 'LAY-2' //设定一个id，防止重复弹出
                    ,
                    btnAlign: 'd'
                    ,
                    moveType: 0 //拖拽模式，0或者1
                    ,
                    fixed: false,
                    btn: ['通过','不通过'],
                    yes:function() {
                        $.ajax({
                        type: "GET",
                        url: "/scholarshipApply/pass",
                        data: {'id':data.id},
                        success: function (res) {
                            if (res.flag){
                                layer.msg('操作成功', {icon: 1});
                                setTimeout(function(){
                                    var index = parent.layer.getFrameIndex(window.name);
                                    parent.layer.close(index);//关闭弹出层
                                    parent.location.reload();//重新加载父页面表格
                                }, 1000);
                            }else {
                                layer.msg(res.msg,{icon:5,offset:"auto",time:2000});//提示框
                            }
                        }
                    })
                    }
                    ,btn2: function() {
                        $.ajax({
                            type: "GET",
                            url: "/scholarshipApply/out",
                            data: {'id':data.id},
                            success: function (res) {
                                if (res.flag){
                                    layer.msg('操作成功', {icon: 1});
                                    setTimeout(function(){
                                        var index = parent.layer.getFrameIndex(window.name);
                                        parent.layer.close(index);//关闭弹出层
                                        parent.location.reload();//重新加载父页面表格
                                    }, 1000);
                                }else {
                                    layer.msg(res.msg,{icon:5,offset:"auto",time:2000});//提示框
                                }
                            }
                        })
                    },
                    content: "guanliyuan-detailExamine.html",
                    shadeClose: true,
                    success: function(layero, index) {
                        var body = layer.getChildFrame('body', index);//获取iframe页的DOM
                        var iframeWin = window[layero.find('iframe')[0]['name']]; //得到iframe页的窗口对象
                        body.find('#id').html(data.id);
                        body.find('#id').val(data.id);
                        body.find('#sname').html(data.sname);
                        body.find('#money').html(data.money+"￥");
                        body.find('#name').html(data.name);
                        body.find('#number').html(data.number);
                        body.find("#clazz").html(data.clazz);
                        body.find("#department").html(data.department);
                        body.find("#major").html(data.major);
                        if(data.gender==1){
                            body.find("#gender").html("男");
                        }else{
                            body.find("#gender").html("女");
                        }
                        $.ajax({
                            type:"POST",
                            url:"/scholarshipApply/edit",
                            data:{
                                "id": data.id,
                                "number": data.number,
                            },
                            dataType:"json",
                            success:function (res) {
                                var s='';
                                for (var relative of res.data.student.relativeList){
                                    s+='<tr>\n' +
                                        '                            <td>'+relative.relationShip+'</td>\n' +
                                        '                            <td>'+relative.relationName+'</td>\n' +
                                        '                            <td>'+relative.relationOccupation+'</td>\n' +
                                        '                            <td>'+relative.relationPhone+'</td>\n' +
                                        '                        </tr>'
                                }
                                body.find('#relTable').html(s);
                                body.find('#politic').html(res.data.student.politic);
                                body.find('#phone').html(res.data.student.phone);
                                body.find('#mail').html(res.data.student.mail);
                                body.find('#native').html(res.data.scholarshipApply.province+'/'+res.data.scholarshipApply.city+'/'+res.data.scholarshipApply.county);
                                if(res.data.scholarshipApply.household==1){
                                    body.find("#household").html("城镇户口");
                                }else{
                                    body.find("#household").html("农村户口");
                                }
                                if(res.data.scholarshipApply.poverty==1){
                                    body.find("#poverty").html("是");
                                }else{
                                    body.find("#poverty").html("否");
                                }
                                body.find('#price').html(res.data.scholarshipApply.price_min+'——'+res.data.scholarshipApply.price_max);
                                body.find('#card').html(res.data.scholarshipApply.card)
                                body.find('#volunteerTime').html(res.data.scholarshipApply.volunteerTime)
                                body.find('#certificate').html(res.data.scholarshipApply.certificate)
                                if(res.data.scholarshipApply.grade==1){
                                    body.find('#grade').html("前10%")
                                }else if(res.data.scholarshipApply.grade==2){
                                    body.find('#grade').html("10%-20%")
                                }else if(res.data.scholarshipApply.grade==3){
                                    body.find('#grade').html("20%-40%")
                                }else {
                                    body.find('#grade').html("40%以下")
                                }
                            }
                        })
                        iframeWin.layui.form.render();
                    },
                })
            } else if(layEvent === 'del') {
                layer.confirm('真的删除行么', function (index) {
                    //向服务端发送删除指令
                    $.ajax({
                        type: "POST",
                        url: "/scholarshipApply/deleteScholarshipApply",
                        data: {'id': data.id},
                        success: function (res) {
                            if (res.flag) {
                                layer.msg('删除成功')
                                obj.del(); //删除对应行（tr）的DOM结构
                                layer.close(index);
                            } else {
                                layer.msg(res.msg)
                            }
                        }
                    })
                });
            }
        });

        $(document).on('click','#searchBtn',function (data) {
            //获取文本框对象
            var search = $('#demoReload')
            //调用数据表格的重载
            table.reload('demo',{
                url:"/scholarshipApply/selectExamine",
                where:{
                    searchResult:search.val()//前端向后端传输的值
                },
                page:{
                    curr:1
                }
            });
        });

    });
</script>
</body>
</html>